package LandlordsGame.LandlordsGame001;

import java.util.ArrayList;
import java.util.Collections;

/**
 * ClassName:PokerGame
 * Package:LandlordsGame.image
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/2/22-21:12
 * @Version:v1.0
 */
public class PokerGame {
    //牌盒
    //♠3 ♦3 ♥3 ♣3
    static ArrayList<String> list = new ArrayList<>();

    //静态代码块(特点：随着类的的加载而加载,而且只执行一次)
    static {
        //准备牌
        /* ♠ ♦ ♥ ♣
         * 3 4 5 6 7 8 9 10 J Q K A 2*/
        String[] color = {"♠", "♦", "♥", "♣"};
        String[] number = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};

        for (String c : color) {
            //c依次表示每一种花色
            for (String n : number) {
                //n依次表示每一个数字
                list.add(c + n);
            }
        }
        list.add("小王");
        list.add("大王");
    }

    public PokerGame() {

        //洗牌
        Collections.shuffle(list);
        //发牌
        ArrayList<String> lord = new ArrayList<>();//底牌集合
        ArrayList<String> player1 = new ArrayList<>();//玩家1
        ArrayList<String> player2 = new ArrayList<>();//玩家2
        ArrayList<String> player3 = new ArrayList<>();//玩家3
        //遍历牌盒得到每一张牌
        for (int i = 0; i < list.size(); i++) {
            String poker = list.get(i);
            if (i <= 2) {
                lord.add(poker);
                continue;
            }
            //给三个玩家轮流发牌
            //i % 3 == 0  给玩家1
            //i % 3 == 1  给玩家2
            //i % 3 == 2  给玩家3
            if (i % 3 == 0) {
                player1.add(poker);
            } else if (i % 3 == 1) {
                player2.add(poker);
            } else if (i % 3 == 2) {
                player3.add(poker);
            }
        }
        //看牌
        lookPoker("底牌", lord);
        lookPoker("鑫哥", player1);
        lookPoker("永哥", player2);
        lookPoker("杰哥", player3);
    }

    //参数一：玩家的名字
    //参数二：每位玩家的名字
    public void lookPoker(String name, ArrayList<String> list) {
        System.out.print(name + ":");
        for (String poker : list) {
            System.out.print(poker + " ");
        }
        System.out.println();
    }
}


